#!/bin/bash

# 压缩日志并备份
compress_log() {
    local log="log.log"
    local backup="log_$(date +%Y%m%d).gz"
    gzip -c $log > $backup
    cp $backup ~/
    gunzip $backup
    echo "日志备份至 ~/$backup"
}

# 统计修改次数
count_modify() {
    local stu=$(grep "修改学生姓名" log.log | wc -l)
    local cls=$(grep "修改课程" log.log | wc -l)
    echo "学生信息修改次数: $stu"
    echo "课程信息修改次数: $cls"
}

# 按学号查询
query_stu() {
    grep "修改学生姓名.*$1" log.log || echo "无记录"
}

# 按课程号查询
query_cls() {
    grep "修改课程.*$1" log.log || echo "无记录"
}

# 共享脚本
share_script() {
    echo "共享地址: https://gitee.com/wangnianx/log/commits/master/log_20251024.gz"
}

# 命令分发
case $1 in
    compress) compress_log ;;
    count) count_modify ;;
    query_stu) query_stu $2 ;;
    query_cls) query_cls $2 ;;
    share) share_script ;;
    *) echo "支持命令: compress/count/query_stu/query_cls/share" ;;
esac
